package com.zyw.mvc.mapping;

import org.springframework.web.servlet.HandlerMapping;
import org.springframework.web.servlet.handler.AbstractUrlHandlerMapping;
import org.springframework.web.servlet.mvc.ParameterizableViewController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author vill on 2014/7/1 10:45.
 * @desc
 */
public class SimpleMapping extends AbstractUrlHandlerMapping implements HandlerMapping {

    public SimpleMapping() {
        logger.info("Setting welcome page");
        ParameterizableViewController controller = new ParameterizableViewController();
        controller.setViewName("redirect:/index.html");
        setRootHandler(controller);
        setOrder(0);
    }

    @Override
    protected Object lookupHandler(String urlPath, HttpServletRequest request)
            throws Exception {
        Object handler = super.lookupHandler(urlPath, request);
        if (handler == null) {
            logger.error("No method mapping for " + request.getRequestURI() + " please check.");
//            throw new Exception("No method mapping for " + request.getRequestURI() + " please check.");
        }
        return handler;
    }
}
